﻿namespace Resonator.Domain.Models
{
	using System.Text;
	using Castle.ActiveRecord;
	using NHibernate.Search.Attributes;
	using NSearch=NHibernate.Search.Search;
	using Field=NHibernate.Search.Attributes.FieldAttribute;

	public abstract class ResonatorModel
	{
		private int _id;

		[PrimaryKey]
		[DocumentId]
		public virtual int Id
		{
			get { return _id; }
			set { _id = value; }
		}

		[Field(Index.Tokenized, Store=Store.No)]
		public virtual string FullText
		{
			get
			{
				StringBuilder sb = new StringBuilder( 1024 );
				GetFullText( sb );
				return sb.ToString();
			}
		}

		protected virtual void GetFullText(StringBuilder builder)
		{
		}

		public static bool operator !=(ResonatorModel resonatorModel1, ResonatorModel resonatorModel2)
		{
			return !Equals( resonatorModel1, resonatorModel2 );
		}

		public static bool operator ==(ResonatorModel resonatorModel1, ResonatorModel resonatorModel2)
		{
			return Equals( resonatorModel1, resonatorModel2 );
		}

		protected bool Equals(ResonatorModel resonatorModel)
		{
			if( resonatorModel == null )
			{
				return false;
			}
			return _id == resonatorModel._id;
		}

		public override bool Equals(object obj)
		{
			if( ReferenceEquals( this, obj ) )
			{
				return true;
			}
			return Equals( obj as ResonatorModel );
		}

		public override int GetHashCode()
		{
			return ToString().GetHashCode();
		}
	}
}